package rs.fon.neuroph.regression;

import java.util.ArrayList;

import org.neuroph.core.NeuralNetwork;
import org.neuroph.core.learning.TrainingElement;

import com.rapidminer.example.Attribute;
import com.rapidminer.example.Example;
import com.rapidminer.example.ExampleSet;
import com.rapidminer.operator.OperatorException;
import com.rapidminer.operator.learner.SimplePredictionModel;

public class NeurophRegressionModel extends SimplePredictionModel {

	private static final long serialVersionUID = -741223153887739663L;

	NeuralNetwork nnet;

	public NeurophRegressionModel(ExampleSet headerExampleSet, NeuralNetwork nnet) {
		super(headerExampleSet);
		this.nnet = nnet;
	}

	
	@Override
	public double predict(Example example) throws OperatorException {

		ArrayList<Double> values = new ArrayList<Double>();
		for (Attribute att: example.getAttributes())
			if(!example.getAttributes().getRole(att).isSpecial())
				values.add(example.getNumericalValue(att));

		
		nnet.setInput((new TrainingElement(values)).getInput());
		nnet.calculate();
		double[] networkOutput = nnet.getOutput();


	return networkOutput[0];
}


}
